package jjn.round2;

/**
 * @author Jiang Jining
 * @since 2023-05-08 22:52
 */
public class Offer57_TwoSum {
    public int[] twoSum(int[] nums, int target) {
        int left = 0, right = nums.length - 1;
        while (left < right) {
            int res = nums[left] + nums[right];
            if (res > target) {
                right--;
            } else if (res < target) {
                left++;
            } else {
                return new int[]{nums[left], nums[right]};
            }
        }
        return new int[1];
    }
}
